<?

session_start();

include('./../config/db_settings.php');
include('./../pms/pms_inc.php');
include('bookmarks_inc.php');

$user_id = $_SESSION[$settings['session_prefix'].'user_id'];
//echo '$user:'.$user;
?>
<html>
<head>
<title>Bookmark Center</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css"
	href="../templates/<? echo $settings['template'] ?>/style_lp.css"
	media="all" />
<script src="../js/google.js" type="text/javascript"></script>
</head>
<script>
function checkUncheckAll(theElement) 
{
   var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length; z++)
	 {
   		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
   		{
	 			theForm[z].checked = theElement.checked;
	 		}
   }
}

function del_confirm(theElement)
{
	 var theForm = theElement.form;
	 var z = 0;
	 var ifChecked = 0;
	 for(z=0; z<theForm.length; z++)
	 {
   		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
   		{
	 			if(theForm[z].checked)
	 			{
	 				ifChecked=1;
	 				break;
	 			}
	 		}
   }
  if(!ifChecked)
  {
  	alert("Please select at least one bookmark that you want to delete.");
  	return false;
  }      
  
var r=confirm("Are you sure you want to delete those selected bookmark(s) permanently?");
if (r==true)
  {
  return true;
  }
else
  {
  return false;
  }
}

</script>
<body>
<?
//Are they logged in or not?
if(!$user_id)
{
	echo "<br><p>You aren't logged in. Please log in first.</p><br>";
}

else
{
	//Get your bookmark count
	//Find the percentage that your inbox is full
	$sql = mysql_query ("SELECT count(*) bm_count FROM ".$db_settings['bookmarks_table']." WHERE user_id='$user_id'");
	$row = mysql_fetch_array ($sql);
	$bm_count = $row['bm_count'];

	$percent = $bm_count/$bookmark_limit;
	$percent = $percent * '100';

	?>
<br>
<center><b><a href="bookmarks.php">Bookmark Centre</a></b><br />
<b><? echo "$bm_count"." of "."$bookmark_limit"." Total  |  "."$percent"."% full"; ?></b><br/>
<?php if($bm_count<$bookmark_limit){ ?><b><a class="" href="./addBookmark.php" target="htk_addbookmark">加新书签</a></b><?php }?>
</center>
<br>
	<?
	$query = "SELECT bookmark_id, post_id, note FROM ".$db_settings['bookmarks_table']."  WHERE user_id='$user_id' order by bookmark_id desc";
	$sqlinbox = mysql_query($query);

	if(!$sqlinbox)
	{ 
		?>
<p><? print '$query: '.$query.mysql_error();?></p>
		<?
	}

	//There are no rows found for the user that is logged in
	elseif (!mysql_num_rows($sqlinbox) )
	{
		?>
<center>
<p><b>You have no bookmarks to display</b></p>
</center>
		<?
	}

	//So if there is not an error, and they apparently do have bookmarks we need to get their information and display it.
	else
	{
		?>
<center>
<form name="frm_1" id="frm_1" method="post" action="deleteBookmark.php">
<table class="normaltab" border="0" cellpadding="5" cellspacing="1"
	width="80%">
	<tr>
		<th width="70px" valign="top">Post</th>
		<th width="" valign="top">Note</th>
		<th width="25px" valign="top">Select</th>
	</tr>
	<?
	$i = 1;
	$c = "a";
	while($inbox = mysql_fetch_array($sqlinbox))
	{
		$note = htmlspecialchars(stripslashes(base64_decode($inbox['note'])));
		$post_id = $inbox['post_id'];
		$bm_id = $inbox['bookmark_id'];

		if($i==1){$c = "a";}
		else {$c = "b";}
		$i= $i * -1;
		?>
	<tr>
		<td valign="top" class="<? echo $c; ?>"><span class="small"><?php if($post_id>0){?><a
			href="./../index.php?id=<? echo $post_id; ?>" target="_blank" style="color: blue"><? echo $post_id; ?></a><?php }else{?>&nbsp;<?php }?></span></td>
		<td valign="top" class="<? echo $c; ?>"><span class="small"><? echo $note; ?></span></td>
		<td valign="top" class="<? echo $c; ?>"><input name="bms[]"
			type="checkbox" value="<? echo $bm_id; ?>"></td>
	</tr>
	<?
	//This ends the while loop
	}
	?>
	<tr>
		<td colspan="2" class="<? echo $c; ?>" align='right'><input
			type="submit" name="Submit" value="Delete Selected"
			onclick="return del_confirm(this)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select/unselect
		all</td>
		<td class="<? echo $c; ?>"><input type="checkbox" name="checkall"
			onclick="checkUncheckAll(this);" /></td>
	</tr>
</table>
</form>
</center>
	<?
	//So this ends the else to see if it is all ok and having bookmarks or not
	}

	//This ends that first thing that checks if you are logged in or not
}
?>

</body>
</html>
